Ext.define('CS.panel.Tab', {
	extend: 'Ext.tab.Panel',

	constructor: function(config) {
		var me = this;

		config = CS.apply({}, config);

		me.callParent([config]);
	},

	showTab: function(card) {
		var item = this.getComponent(card);

		if (item && item.tab) {
			item.tab.show();
			this.setActiveTab(item);
		}
	},

	hideTab: function(card) {
		var item = this.getComponent(card), toActivate;

		if (item && item.tab) {
			item.tab.hide();

			if ((toActivate = this.tabBar.items.indexOf(this.tabBar.findNextActivatable(item.tab))) !== -1) {
				this.setActiveTab(toActivate);
			}
		}
	},

	loadTab: function(id, title, url, notActive) {
		var me = this, options = {
			panelType: 'list',
			closable: true
		};

		if (Ext.isString(id)) {
			CS.apply(options, {
				panelId: id,
				title: title,
				html: '<iframe frameborder="0" width=100% height=100% src="' + CS.getRootUrl(url) + '" />'
			});
		} else {
			CS.apply(options, id);
		}

		var tab = CS.create(Ext.create('CS.panel.BasePanel', options).getConfig());
		me.add(tab);

		if (notActive != true) {
			me.showTab(tab);
		}

		return tab;
	}

});
